var time=0;//时间
var times=0;//次数
var start=0;//记录当前哪张图片显示
var pictures=document.getElementsByClassName("content");
var lines=document.getElementsByClassName("line");
function clock(){/*设置css属性和自动切换图片*/
    changeLine((start%pictures.length)+1);
    start++;
    if(times){
        time=10000;
        times=0;
    }
    else
        time=0;
    window.setTimeout("clock()",2000+time);
}
function show(num){
    pictures[num].style.display="block";
    lines[num].style.borderColor="white";
}
function hide(num){
    pictures[num].style.display="none";
    lines[num].style.borderColor="gray";
}
function changeButton(select){ /*按下左右边按钮时改变按顺序图片的显示*/
    for(var i=0;i<pictures.length;i++){
        var get=pictures[i].style.display;
        if(get!="none"){
            hide(i);
            times=1;
            if(select==0){
                if(i==pictures.length-1){
                    show(0);
                    start=0;
                }
                else{
                    show(i+1);
                    start=i+1;
                }
                break;
            }
            else{
                if(i==0){
                    show(pictures.length-1)
                    start=pictures.length-1;
                }
                else{
                    show(i-1);
                    start=i-1;
                }
                break;
            }
        }
    }

}
function  changeLine(num){ /*随意改变图片的显示*/
    for(var i=0;i<pictures.length;i++){
        if(num==i+1){
            show(i);
            start=i;
        }
        else{
            hide(i);
        }
    }
}
function changeTimes(){
    times=1;
}

//监听事件
var body=document.getElementsByTagName('body');
body[0].onload=clock();

var button = document.getElementsByClassName('button');
for (var i = 0; i < button.length; i++) {
    button[i].num = i;
    button[i].addEventListener('click', function () {
        changeButton(this.num);
    }, false);
};

for(var i=0;i<lines.length;i++){
    lines[i].num=i;
    lines[i].addEventListener('click',function () {
        changeLine(this.num+1);
        changeTimes();
    },false)
};





